import { mapGetters } from 'vuex'
import { getAddressNextValue } from '@/common/api/address'

export default {
  data() {
    return {}
  },
  computed: {
    ...mapGetters(['userId', 'clientId', 'org', 'user']),
    isSubmit() {
      return this.user.scopes.includes('indoneBI')
    },
    isSYSTEM() {
      // 系统后台查所有
      return this.org.orgClass === 'org_credit_sys'
    },
    searchParamsSubmit() {
      const params = {}
      if (!this.isSYSTEM) {
        const { queryAddressCode, clientOrgClassType } = this.user
        if (!queryAddressCode) {
          this.$message.error('机构配置出错，未添加机构地址')
          throw new Error('该机构没有地址')
        }
        if (this.isSubmit) {
          params.orWhereAndTemplate = 2
          params['orWhereAnd.submit_client_id.eq'] = this.clientId
          params['orWhereAnd.bank_type.in'] = clientOrgClassType
          params['orWhereAnd.submit_client_address_code.gt'] = queryAddressCode
          params['orWhereAnd.submit_client_address_code.lt'] = getAddressNextValue(queryAddressCode)
          params['orWhereAnd.bank_type.eq'] = clientOrgClassType
        } else {
          params['submit_person.eq'] = this.userId
        }
      }
      return params
    },
    searchParamsConfirm() {
      const params = {}
      if (!this.isSYSTEM) {
        const { queryAddressCode, clientOrgClassType } = this.user
        if (!queryAddressCode) {
          this.$message.error('机构配置出错，未添加机构地址')
          throw new Error('该机构没有地址')
        }
        if (this.isSubmit) {
          params.orWhereAndTemplate = 2
          params['orWhereAnd.submit_client_id.eq'] = this.clientId
          params['orWhereAnd.bank_type.in'] = clientOrgClassType
          params['orWhereAnd.submit_bank_address_code.gt'] = queryAddressCode
          params['orWhereAnd.submit_bank_address_code.lt'] = getAddressNextValue(queryAddressCode)
          params['orWhereAnd.bank_type.eq'] = clientOrgClassType
        } else {
          params['submit_person.eq'] = this.userId
        }
        params['bank_type.eq'] = clientOrgClassType
      }
      return params
    },
  },
  methods: {},
}
